package myThread;

class Mythread1 extends Thread{
    public Mythread1(String name) {
        super(name);
    }

    //run 相当于进程的入口
    @Override
    public void run() {
        while(true){
            System.out.println("hello thread");
            //调用这个方法会抛异常,由于这个类是继承与Thread的,run方法是继承与Thread中的run
            //子类重写方法抛出的异常,必须是父类方法异常的子类或相同类型,且不能抛出更宽泛的异常
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
public class demo6 {
    public static void main(String[] args) {
        Thread t1 = new Thread(()->{
            while(true){
                System.out.println("hello t1");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        },"这是线程一");//线程命名为th1
        t1.start();

        Mythread1 t2 = new Mythread1("这是线程二");
        t2.start();
    }
}
